import { Form, Input, Modal } from 'antd'
import React from 'react'

export default function Dailog(props) {
    const { modalRef, visible, closeModal, handleAdd, isUpdate, handleUpdate } = props
    const handleOk = async () => {
        const res = await modalRef.validateFields()
        if (isUpdate) {
            handleUpdate(res)
        } else {
            handleAdd(res)
        }
        handleCancel()
    }
    const handleCancel = () => {
        closeModal()
    }
    return (
        <div>
            <Modal title={'添加'} visible={visible} onOk={handleOk} onCancel={handleCancel}>
                <Form
                    form={modalRef}
                >
                    <Form.Item
                        label="姓名"
                        name="name"
                        rules={[
                            {
                                required: true,
                                message: '请输入姓名'
                            }
                        ]}
                    >
                        <Input />
                    </Form.Item>

                    <Form.Item
                        label="年龄"
                        name="age"
                        rules={[
                            {
                                required: true,
                                message: '请输入年龄'
                            }
                        ]}
                    >
                        <Input />
                    </Form.Item>

                    <Form.Item
                        label="地址"
                        name="address"
                        rules={[
                            {
                                required: true,
                                message: '请输入地址'
                            }
                        ]}
                    >
                        <Input />
                    </Form.Item>
                </Form>
            </Modal>
        </div>
    )
}
